module(..., package.seeall)

local function create_style(v)
    local s = lvgl.style_t()
    lvgl.style_init(s)
    if not v then return s end
    -- 设置背景
    if v.bg then s = set_bg(s, v.bg) end
    -- 设置边框
    if v.border then s = set_border(s, v.border) end
    -- 设置阴影
    if v.shadow then s = set_shadow(s, v.shadow) end
    -- 设置外框线
    if v.outline then s = set_outline(s, v.outline) end
    return s
end

function create(p, v)
    c = lvgl.cont_create(p, nil)
    lvgl.cont_set_fit(c, lvgl.FIT_NONE)
    lvgl.obj_set_click(c, v.click or true)
    lvgl.obj_set_size(c, v.W or 100, v.H or 100)
    -- lvgl.cont_set_layout(c, lvgl.LAYOUT_OFF)
    -- lvgl.obj_set_auto_realign(Titlecont, true)                   
    lvgl.obj_align(c, v.align_to, v.align or lvgl.ALIGN_CENTER, v.align_x or 0,
                   v.align_y or 0)

    if v.event then lvgl.obj_set_event_cb(c, v.event) end
    lvgl.obj_add_style(c, lvgl.CONT_PART_MAIN, create_style(v.style))
    return c
end

-- create(lvgl.scr_act(), {
--     W = 200,
--     H = 100,
--     click = false,
--     style = {
--         border = {color = 0x0f0f0f, width = 2, opa = 30},
--         shadow = {spread = 30, color = 0xff00f0},
--         bg = {
--             radius = 10,
--             color = 0x0f0ff0,
--             opa = 150,
--             grad = {color = 0x0f0f0f}
--         }
--     }
-- })
